package com.sky.cost.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sky.common.annotation.Log;
import com.sky.common.core.controller.BaseController;
import com.sky.common.core.domain.AjaxResult;
import com.sky.common.enums.BusinessType;
import com.sky.cost.domain.TbProjectCost;
import com.sky.cost.service.ITbProjectCostService;
import com.sky.common.utils.poi.ExcelUtil;
import com.sky.common.core.page.TableDataInfo;

/**
 * 项目成本明细Controller
 * 
 * @author ruoyi
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/cost/cost")
public class TbProjectCostController extends BaseController
{
    @Autowired
    private ITbProjectCostService tbProjectCostService;

    /**
     * 查询项目成本明细列表
     */
    @PreAuthorize("@ss.hasPermi('cost:cost:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbProjectCost tbProjectCost)
    {
        startPage();
        List<TbProjectCost> list = tbProjectCostService.selectTbProjectCostList(tbProjectCost);
        return getDataTable(list);
    }

    /**
     * 导出项目成本明细列表
     */
    @PreAuthorize("@ss.hasPermi('cost:cost:export')")
    @Log(title = "项目成本明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbProjectCost tbProjectCost)
    {
        List<TbProjectCost> list = tbProjectCostService.selectTbProjectCostList(tbProjectCost);
        ExcelUtil<TbProjectCost> util = new ExcelUtil<TbProjectCost>(TbProjectCost.class);
        util.exportExcel(response, list, "项目成本明细数据");
    }

    /**
     * 获取项目成本明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('cost:cost:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbProjectCostService.selectTbProjectCostById(id));
    }

    /**
     * 新增项目成本明细
     */
    @PreAuthorize("@ss.hasPermi('cost:cost:add')")
    @Log(title = "项目成本明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbProjectCost tbProjectCost)
    {
        return toAjax(tbProjectCostService.insertTbProjectCost(tbProjectCost));
    }

    /**
     * 修改项目成本明细
     */
    @PreAuthorize("@ss.hasPermi('cost:cost:edit')")
    @Log(title = "项目成本明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbProjectCost tbProjectCost)
    {
        return toAjax(tbProjectCostService.updateTbProjectCost(tbProjectCost));
    }

    /**
     * 删除项目成本明细
     */
    @PreAuthorize("@ss.hasPermi('cost:cost:remove')")
    @Log(title = "项目成本明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbProjectCostService.deleteTbProjectCostByIds(ids));
    }
}
